import json
import os

from libs.utils import logging


def test1():
    import paddle
    logging.info("PaddlePaddle version: ", paddle.__version__)



def test2():
    # 初始化 OCR 模型
    from paddleocr import PaddleOCR
    ocr = PaddleOCR(use_angle_cls=True, lang='ch')  # 支持中文

    # 获取当前脚本所在目录
    current_dir = os.path.dirname(os.path.abspath(__file__))
    img_path = './data/image.jpg'
    img_path = os.path.join(current_dir, img_path)
    print(img_path)


    # 执行 OCR
    result = ocr.ocr(img_path, cls=True)[0]
    for line in result:
        logging.info(json.dumps(line, ensure_ascii=False))  # 将列表转换为 JSON 字符串





if __name__ == '__main__':
    test2()